package com.telephone.purchase.service.impl;

import com.telephone.purchase.dao.OrderDao;
import com.telephone.purchase.entity.Order;
import com.telephone.purchase.model.OrderInfoResponse;
import com.telephone.purchase.service.OrderInfoServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fengyingeng
 * @date 2019/9/5 9:58
 * Description:
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoServie {
    @Autowired
    private OrderDao orderDao;
    @Override
    public List<OrderInfoResponse> getListInfos(String phoneNumber) {

         List<OrderInfoResponse> orderInfoResponses = new ArrayList<>();

         List<Order> orderList = orderDao.getListInfo(phoneNumber);

         for (int i = 0; i < orderList.size(); i++){
             Order order = orderList.get(i);
             OrderInfoResponse orderInfoResponse = new OrderInfoResponse();
             orderInfoResponse.setOrder(order);
             //获取套餐ID,根据套餐ID获取商品ID，再根商品ID获取商品的图片URL
             String iconUrl = this.getGoodUrl(this.getGoodId(order.getPackageId()));
             orderInfoResponse.setIconUrl(iconUrl);
             orderInfoResponses.add(orderInfoResponse);
         }
         return orderInfoResponses;
    }

    @Override
    public Long getGoodId(Long packageId) {
        return orderDao.getGoodId(packageId);
    }

    @Override
    public String getGoodUrl(Long goodId) {
        return orderDao.getGoodUrl(goodId);
    }
}
